package com.st.vmall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.st.vmall.entity.Type;
import com.st.vmall.mapper.TypeMapper;
import com.st.vmall.service.ITypeService;

@Service
public class TypeServiceImpl implements ITypeService{

	@Autowired
	private TypeMapper typeMapper;
	
	@Override
	public int add(Type type) {
		return typeMapper.insert(type);
	}

	@Override
	public List<Type> getFirst() {
		return typeMapper.selectByParent(null);
	}
	
	@Override
	public List<Type> getSecond(Integer parent) {
		return typeMapper.selectByParent(parent);
	}

	@Override
	public PageInfo search(Type type, Integer page, Integer limit) {
		/*
		 * pageHelper插件
		 */
		PageHelper.startPage(page, limit);
		List list = typeMapper.selectByType(type);
		PageInfo pageInfo = new PageInfo(list);
		
		return pageInfo;
	}

	@Override
	public int delete(Integer id) {
		return typeMapper.delete(id);
	}

	@Override
	public int edit(Type type) {
		return typeMapper.update(type);
	}

}
